package cn.jiangjiesheng.bootstrap.commons.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * Created by dev@jiangjiesheng.cn on 2020/7/28.
 */
public class JsonUtil {

    public static <T> List<T> parseArray(Object records, Class<T> clazz) {
        if (records == null) {
            return Lists.newArrayList();
        }

        if(!(records instanceof List)){
            return Lists.newArrayList();
        }

        if (CollectionUtils.isEmpty((List)records)) {
            return Lists.newArrayList();
        }

        return JSONArray.parseArray(JSON.toJSONString(records), clazz);
    }
}
